package com.ecustbookstore.mymall.controller;

import com.ecustbookstore.mymall.common.CommonResponse;
import com.ecustbookstore.mymall.mbg.pojo.PmsBrand;
import com.ecustbookstore.mymall.service.PmsBrandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * @description: 对商品品牌进行管理
 * @author: Tian
 * @time: 2021/5/20 23:05
 */
@Api(tags = "PmsBrandController", description = "商品品牌管理")
@RestController
@RequestMapping("/brand")
public class PmsBrandController {

    @Resource
    private PmsBrandService pmsBrandService;

    private static final Logger logger = LoggerFactory.getLogger(PmsBrandController.class);

    @ApiOperation("增加品牌")
    @PostMapping("/add")
    public CommonResponse addBrand(@RequestBody PmsBrand pmsBrand) {
        return pmsBrandService.addBrand(pmsBrand);
    }

    @ApiOperation("删除指定id品牌")
    @DeleteMapping("/delete/{id}")
    public CommonResponse deleteBrand(@PathVariable("id") Long id) {
        return pmsBrandService.deleteBrand(id);
    }

    @ApiOperation("更新指定id品牌信息")
    @PostMapping("/update/{id}")
    public CommonResponse updateBrand(@RequestBody PmsBrand pmsBrand) {
        return pmsBrandService.updateBrand(pmsBrand);
    }

    @ApiOperation("获取指定id的品牌详情")
    @GetMapping("/selectOne/{id}")
    public CommonResponse selectOne(@PathVariable Long id) {
        return pmsBrandService.selectBrandById(id);
    }

    /**
     * 根据品牌名称分页获取品牌列表
     *
     * @param
     * @return
     */
    @ApiOperation("分页查询品牌列表")
    @GetMapping("/list")
    public CommonResponse<List<PmsBrand>> getList(@RequestParam(value = "keyword", required = false) String keyword,
                                                  @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                  @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        return pmsBrandService.getList(keyword, pageNum, pageSize);
    }

    /**
     * 获取全部品牌名称列表
     * 此接口很鸡肋
     * @return
     */
    @GetMapping("/listAll")
    public CommonResponse<List<PmsBrand>> listAllBrand() {
        return pmsBrandService.listAllBrand();
    }
}   
